Fix NoSuchElementException for listeners with inferred types#669
Merged
LakshanWeerasinghe merged 4 commits intoballerina-platform:1.6.xfrom Feb 2, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a NoSuchElementException that occurs when processing listener declarations without explicit type descriptors (e.g., listener list = new http:Listener(8080)). The fix properly handles type inference by checking if a type descriptor is present before accessing it, and extracting the type from the ExplicitNewExpressionNode initializer when needed.
Changes:
- Added logic to handle three cases for listener type extraction: explicit type descriptors, type inferred from ExplicitNewExpressionNode, and fallback to semantic model type inference
- Added test case with a listener declaration using type inference to validate the fix
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| CodeAnalyzer.java | Fixed NoSuchElementException by checking typeDescriptor presence before calling get(), and added logic to extract type from ExplicitNewExpressionNode initializer for inferred types |
| project_8/main.bal | Test case demonstrating listener with inferred type syntax |
| project_8/Ballerina.toml | Test project configuration |
| project_with_only_listener.json | Expected test output for the inferred-type listener test case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ator-ls-extension/src/test/resources/get_design_model/config/project_with_only_listener.json
Show resolved
Hide resolved
...ator-ls-extension/src/test/resources/get_design_model/config/project_with_only_listener.json
Outdated
Show resolved
Hide resolved
...-model-generator-core/src/main/java/io/ballerina/designmodelgenerator/core/CodeAnalyzer.java
Outdated
Show resolved
Hide resolved
...-model-generator-core/src/main/java/io/ballerina/designmodelgenerator/core/CodeAnalyzer.java
Show resolved
Hide resolved
LakshanWeerasinghe
approved these changes
Feb 2, 2026
Contributor
|
@pasindufernando1 can you please attach the related GH issue in the PR description? |
54 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This PR handles cases of NoSuchElementExceptions in CodeAnalyzer.visit(ListenerDeclarationNode) when processing listener declarations without explicit type descriptors (e.g., listener list = new http:Listener(8080)). The code now handles both explicit type declarations and type-inferred listeners by extracting the type from the ExplicitNewExpressionNode initializer when no type descriptor is present.
Fixes : wso2/product-ballerina-integrator#1887
Screen.Recording.2026-02-02.at.13.00.55.mov